package com.lq.educationsystem.lqsubject.controller;

import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import com.lq.educationsystem.common.util.ResultPage;
import com.lq.educationsystem.common.vo.SubjectPageVo;
import com.lq.educationsystem.lqsubject.entiy.SubjectTb;
import com.lq.educationsystem.lqsubject.service.SubjectBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "课程管理接口")
@RequestMapping("/subject/base")
@RestController
public class SubjectBaseController {

    //导入service
    @Autowired
    SubjectBaseService subjectBaseService;
    //增加

    @Operation(summary = "插入学生信息")
    @PostMapping("/insert")
    public Result insertInfo(@RequestBody SubjectTb subjectTb){
        //插入数据
        subjectBaseService.insetInfo(subjectTb);
        return ResultBuild.buildOk();
    }
    //删除
    @Operation(summary = "通过id删除课程")
    @PostMapping("/delete")
    public Result deleteById(@RequestBody SubjectTb subjectTb){
        //获取id

        Integer subjectId = subjectTb.getSubjectId();
        //删除
        subjectBaseService.deleteById(subjectId);
        return ResultBuild.buildOk();

    }
    //更新

    @Operation(summary = "更新课程信息")
    @PostMapping("/update")
    public Result updateInfo(@RequestBody SubjectTb subjectTb){

        //更新数据时的id

        subjectBaseService.updateInfo(subjectTb);
        return ResultBuild.buildOk();
    }
    //通过id查询
    @Operation(summary = "通过课程id查询可能信息")
    @PostMapping("/querybyid")
    public Result<SubjectTb> queryById(@RequestBody SubjectTb subjectTb){
        Integer subjectId = subjectTb.getSubjectId();
        //通过id查询
        Result subjectInfo= subjectBaseService.queryById(subjectId);

        return subjectInfo;
    }

    //分页查询的功能
    @Operation(summary = "分页查询课程信息")
    @PostMapping("/query")
    public ResultPage<SubjectTb> queryList(@RequestBody SubjectPageVo subjectPageVo){
        ResultPage<SubjectTb>  resultPage= subjectBaseService.queryList(subjectPageVo );
        return resultPage;
    }

    //批量查询课程id
    @Operation(summary = "批量查询课程信息")
    @PostMapping("/query/batch/subject")
    public ResultPage<SubjectTb> queryBatchSubjectInfoBySubjectIdList(@RequestBody List<Integer> subjectIdListInfo){
        //批量查询数据
        ResultPage<SubjectTb> subjectTbResultPage= subjectBaseService.queryBatchSubjectInfoBySubjectIdList(subjectIdListInfo);
        return subjectTbResultPage;
    }
}
